<?php
namespace slinks\extensions\amf\zend;


use slinks\core\DependencyInjection\ContainerInterface;

/**
 * Extends Zend_Server_Reflection_Class to allow amf RemoteMethods to be invoked directly from a Slinks container. 
 * 
 * NOTE: This class should not be used as a general replacement for Zend_Server_Reflection_Class since it purposely brekas some functionality. 
 *       This is done so we can extend the Zend_Amf_Server without modifications to the Zend code. 
 *       
 * @author Navid Mitchell
 *
 */
class ServiceAwareZendServerReflectionClass extends \Zend_Server_Reflection_Class{
	
	/**
	 * @var string $serviceName the name of the serivce this class proxies. 
	 */
	private $serviceName;
	
	/**
	 * @var ContainerInterface that contains the service.
	 */
	private $serviceContainer;
	
	
    /**
     * Create a ServiceAwareZendServerReflectionClass for the given service container and serviceName
     * 
	 * @param string $serviceName the name of the Slinks service. 
	 * @param array $serviceMethodNames an array of method names that can be called for the given service.
     */
    public function __construct($serviceName,array $serviceMethodNames,ContainerInterface $serviceContainer){
        $this->serviceName = $serviceName;
        $this->serviceContainer = $serviceContainer;
        
        // This is set to the service name. It cannot be set currently maybe later this will be supported. 
        // This allows for the service to be prefixed with a namespace to avoid name collisions. 
        $this->_namespace = $serviceName;
        
        // add reflection methods for all of the method names. 
         foreach ($serviceMethodNames as $method) {

            $this->_methods[] = new ServiceAwareZendServerReflectionMethod($this, $method);
        }
    }
    
    
    /**
     * Overriden method to provide instance from Slinks container. 
     */
    public function newInstance(){
    	return $this->serviceContainer->get($this->serviceName);
    }
    
    
    public function getName(){
    	return $this->serviceName;
    }
    
}

